﻿using Prism.Commands;
using Prism.Mvvm;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ManYanPrism.Shell.ViewModels
{
    public class NavViewModel:BindableBase, INavigationAware
    {
        #region 字段
        private readonly IRegionManager _regionManager;
        private IRegionNavigationJournal _journal;
        #endregion


        #region 命令
        private DelegateCommand _openCommand;
        public DelegateCommand OpenCommand =>
            _openCommand ?? (_openCommand = new DelegateCommand(ExecuteOpenCommand));

        private DelegateCommand _goBackCommand;
        public DelegateCommand GoBackCommand => _goBackCommand ?? (_goBackCommand=new DelegateCommand(ExcuteGoBackCommand));
        #endregion

        #region execute
        void ExecuteOpenCommand()
        {
            Navigate("DeviceList");
        }
        private void Navigate(string navigatePath)
        {
            if (navigatePath != null)
                _regionManager.RequestNavigate("mainContent", navigatePath);
        }
        public void ExcuteGoBackCommand()
        {
            _journal.GoBack();
        }

        public void OnNavigatedTo(NavigationContext navigationContext)
        {
            _journal = navigationContext.NavigationService.Journal;
        }

        public bool IsNavigationTarget(NavigationContext navigationContext)
        {
            return true;
        }

        public void OnNavigatedFrom(NavigationContext navigationContext)
        {
            throw new NotImplementedException();
        }
        #endregion

        public NavViewModel(IRegionManager regionManager)
        {
            _regionManager =regionManager;
        }


      
    }
}
